"""
 索引类的创建，用于全文搜索
"""
from haystack import indexes
from recruit.models import Recruit


class EnterpriseIndexes(indexes.SearchIndex, indexes.Indexable):
    # 搜索职位
    text = indexes.CharField(document=True, use_template=True)
    # {{object.id}}
    # {{object.jobname}}
    # {{object.salary}}
    # {{object.education}}
    # {{object.city}}
    id = indexes.IntegerField(model_attr='id')
    jobname = indexes.CharField(model_attr='jobname')
    salary = indexes.CharField(model_attr='salary')
    education = indexes.CharField(model_attr='education')
    city = indexes.CharField(model_attr='city')
    # 返回建立索引的模型类
    def get_model(self):
        """返回建立索引的模型类"""
        return Recruit

    # 返回要建立索引的数据查询集
    def index_queryset(self, using=None):
        return self.get_model().objects.filter(state=1)